//
//  AboutUsTableViewController.m
//  LPTClient
//
//  Created by apple on 2018/12/7.
//  Copyright © 2018 zhaodd. All rights reserved.
//

#import "AboutUsTableViewController.h"
#import "LPTWebViewController.h"

@interface AboutUsTableViewController ()

@property (nonatomic, strong) NSArray *array;

@end

@implementation AboutUsTableViewController

+ (instancetype)instance
{
    UIStoryboard * storyBoard = [UIStoryboard storyboardWithName:@"Mine" bundle:nil];
    AboutUsTableViewController *vc = [storyBoard instantiateViewControllerWithIdentifier:@"AboutUsTableViewController"];
    return vc;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.tableView.tableFooterView = [UIView new];
    
    NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary];
    //NSString *app_Name = [infoDictionary objectForKey:@"CFBundleDisplayName"];
    NSString *app_Version = [infoDictionary objectForKey:@"CFBundleShortVersionString"];
    
    self.tableView.rowHeight = UITableViewAutomaticDimension;
    self.tableView.estimatedRowHeight = 44;
    
    NSArray *array = @[@{@"title":@"当前版本", @"desc":app_Version , @"hasDetail":[NSNumber numberWithBool:NO]},
                       @{@"title":@"检查更新", @"desc":@"" , @"hasDetail":[NSNumber numberWithBool:YES]},
                       @{@"title":@"关于", @"desc":@"" , @"hasDetail":[NSNumber numberWithBool:YES]}];
    self.array = array;
    
    [self.tableView reloadData];
}

#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 2;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    if (section == 1) {
        return self.array.count;
    }
    return 1;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    NSInteger section = indexPath.section;
    
    if (section == 0) {
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"AboutUsTable1" forIndexPath:indexPath];

        return cell;
    }else if (section == 1) {
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"AboutUsTable2" forIndexPath:indexPath];
        
        NSDictionary *dict = self.array[indexPath.row];
        NSString *title = dict[@"title"];
        NSString *desc = dict[@"desc"];
        BOOL hasDetail = [dict[@"hasDetail"] boolValue];
        
        cell.textLabel.text = title;
        cell.detailTextLabel.text = desc;
        if (hasDetail) {
            cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
        } else {
            cell.accessoryType = UITableViewCellAccessoryNone;
        }
            
        
        return cell;
    }
    
    return nil;
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
 
    if (indexPath.section == 1) {
        if (indexPath.row == 1) {
            // 检查更新
            [self requestUpdateVersion];
        } else if (indexPath.row == 2) {
            // 关于
            // 去网页
            LPTWebViewController *vc = [LPTWebViewController instanceWithUrl:@"https://doctor.5ixlz.com/common/article_detail?slug=about-us"];
            [self.navigationController pushViewController:vc animated:YES];

        }
    }
}

- (void)requestUpdateVersion
{
    
}

/*
// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the specified item to be editable.
    return YES;
}
*/

/*
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        // Delete the row from the data source
        [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
    } else if (editingStyle == UITableViewCellEditingStyleInsert) {
        // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
    }   
}
*/

/*
// Override to support rearranging the table view.
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
}
*/

/*
// Override to support conditional rearranging of the table view.
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the item to be re-orderable.
    return YES;
}
*/

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
